#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *licenseKeyFormatting(char *s, int k)
{
    int len = strlen(s);
    int start = 0;
    char ch[len];
    for (int i = 0; i < len; ++i)
    {
        if (s[i] != '-')
            ch[start++] = s[i] >= 'a' ? s[i] - ('a' - 'A') : s[i];//将'-'去除，并转大小写
    }
    char *p = malloc(sizeof(char)*(start / k + start ));//分配空间大小
    int pos = 0;
    for (int i = 0; i < start; ++i)
    {
        p[pos++] = ch[i];
        if ((i + 1) % k == start % k && i < start - 1)
        {
            p[pos++] = '-';
        }
    }
    return p;
}

int main()
{
    char s[] = "abb--E2f1-lk";
    int k = 4;
    char *ptr = licenseKeyFormatting(s, k);
    printf("%s\n", ptr);
    free(ptr);
    ptr = NULL;
    return 0;
}